package net.xdclass.jvm;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author zhaowei
 * @Description TODO
 * @Remark 有问题直接联系我
 * @Version 1.0
 **/
public class ClassLoaderTest {

    public static void main(String[] args) throws Exception {

    }


    public static void  test2()throws Exception{
        MyClassLoader myClassLoader = new MyClassLoader("/Users/xdclass/Desktop/");
        //加载指定类
        Class<?> clazz = myClassLoader.loadClass("HeapDemo");
        Object obj = clazz.getDeclaredConstructor().newInstance();
        System.out.println(obj.getClass());

        System.out.println(obj instanceof HeapDemo);

        System.out.println(obj.getClass().getName()+"------"+obj.getClass().getClassLoader().getClass().getName()+"类加载器加载");

        System.out.println(HeapDemo.class.getName()+"-------"+HeapDemo.class.getClassLoader().getClass().getName()+"类加载器加载");

        System.out.println(HeapDemo.class.getClassLoader().getClass().getName());
        System.out.println(HeapDemo.class.getClassLoader().getParent().getClass().getName());
        System.out.println(HeapDemo.class.getClassLoader().getParent().getParent());
    }


    public static void  test1()throws Exception{
        MyClassLoader myClassLoader = new MyClassLoader("/Users/xdclass/Desktop/");

        //加载指定类
        Class<?> clazz = myClassLoader.loadClass("HeapDemo");
        Object obj = clazz.getDeclaredConstructor().newInstance();
        System.out.println(obj.getClass().getName()+"------"+obj.getClass().getClassLoader().getClass().getName()+"类加载器加载");

    }

}
